#! /usr/bin/env python
#-*- encoding:utf-8 -*-

class ConfigWindow:
    def __init__(self,gxml,cfg,ds):
        self.xml=gxml
        self.cfg=cfg
        self.ds=ds
        self.win=self.xml.get_widget('config_window')
        #self.win.hide_on_delete()
        self.win.connect("destroy",self.on_quit)
        self.win.connect('delete-event',self.on_delete)
        self.xml.get_widget('rb_qt_single_sina').connect('toggled',self.on_rb_conn,'qt_single','sina')
        self.xml.get_widget('rb_qt_single_w618').connect('toggled',self.on_rb_conn,'qt_single','w618')
        self.xml.get_widget('rb_qt_multi_sina').connect('toggled',self.on_rb_conn,'qt_multi','sina')
        self.xml.get_widget('rb_img_sina').connect('toggled',self.on_rb_conn,'img','sina')
        self.xml.get_widget('rb_img_sohu').connect('toggled',self.on_rb_conn,'img','sohu')
        self.xml.get_widget('btn_cfgwin_close').connect('clicked',self.on_quit)
    
    def on_delete(self,w,e):
        w.hide()
        return True
        
    def on_quit(self,w):
        self.hide()
        
    def on_rb_conn(self,w,item,value):
        self.cfg["conn"][item]=value
        self.update()
        
    def update(self):
        self.ds.set_config(self.cfg['conn'])
        
    def show(self):
        self.win.show()
        
    def hide(self):
        self.win.hide()